using System;
using System.Xml;
using CommunityServer.Components;

namespace CommunityServerStuff.CSModules
{
    class ContentCensorshipModule : ICSModule
    {

        public ContentCensorshipModule()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public void Init(CSApplication csa, XmlNode node)
        {
            csa.PrePostUpdate += new CSPostEventHandler(csa_BeforeProcessPost);
        }

        private void csa_BeforeProcessPost(IContent content, CSPostEventArgs e)
        {
            if (e.ApplicationType == ApplicationType.ContentManagement && e.State != ObjectState.Delete)
            {
                Content c = content as Content;
                if (c != null && CSContext.Current.SiteSettings.EnableCensorship)
                {
                    c.FormattedBody = Transforms.CensorPost(c.FormattedBody);
                    c.Title = Transforms.CensorPost(c.Title);
                }
            }
        }
    }
}
